<%@ page contentType="text/html; charset=utf-8" language="java"
	import="java.sql.*" errorPage=""%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
<title>Untitled Document</title>
</head>

<body>
	<table width="100%" height="100%" border="2">
		<tr>
			<td width="22%" height="95"><img src="logo.png" width="163"
				height="154" alt="Logo" /></td>
			<td width="78%"><h1>Island Auctions</h1>
				<p>Turning Junk Into Money</p></td>
		</tr>
		<tr>
			<td valign="top"><p>
					<a href="index.jsp">Home</a>
				</p>
				<p>
					<a href="Browse.jsp">Browse</a>
				</p>
				<p>
					<a href="SearchByType.jsp">Search</a>
				</p>
				<p>
					<a href="profile.jsp">Profile</a>
				</p>
				<p>
					<a href="Users.jsp">Users</a>
				</p> <%
 	try {
 		if (session.getValue("login") != null) {
 %>
				<p>
					<a href="Logout.jsp">Logout</a>
				</p> <%
 	} else {
 %>
				<p>
					<a href="login.jsp">Login</a>
				</p> <%
 	}
 	} catch (java.lang.IllegalStateException e) {
 %>
				<p>
					<a href="login.jsp">Login</a>
				</p> <%
					}
				%> <%
 	try {
 		if (session.getValue("empLevel") == "1") {
 %>
				<p>
					<a href="ManageEmployees.jsp">(Manage Employees)</a>
				</p></td>
			<%
				} else {
			%>
			<br>
			<%
				}
				} catch (java.lang.IllegalStateException e) {
			%>
			<br>
			<%
				}
			%>
			<td valign="top">

				<form name="itemName" action="ListSalesItemName.jsp" method="post">

					<span style="font-size: 10pt">Item Name:</span> <input id="Start" name="itemName" type="text" />
					&nbsp; 
					<input id="Button1" style="width: 70px" type="button" value="List" onclick="return ItemName_OnClick()" /> &nbsp; <br />
				</form> <br></br>
				<p>
					<a href="ListSalesCustomerName.jsp">By Item Name</a>
				</p> <%
				
				String itemName = request.getParameter("itemName");
				if ((itemName != null))
				{
					if (itemName.trim().equals(""))
					{
						response.sendRedirect("ListSalesItemName.jsp");
					}
					else
					{

					}
				}
				String mysJDBCDriver = "com.mysql.jdbc.Driver";
				String mysURL = "jdbc:mysql://mysql2.cs.stonybrook.edu:3306/jedale";
				String mysUserID = "jedale";
				String mysPassword = "107200855";

				String Id = request.getParameter("UserName");
				java.sql.Connection conn = null;

				try {
					Class.forName(mysJDBCDriver).newInstance();
					java.util.Properties sysprops = System.getProperties();
					sysprops.put("user", mysUserID);
					sysprops.put("password", mysPassword);

					//connect to the database
					conn = java.sql.DriverManager.getConnection(mysURL, sysprops);
					System.out
							.println("Connected successfully to database using JConnect");

					java.sql.ResultSet rs;
					java.sql.Statement stmt1 = conn.createStatement();
			%>
				<h2>By Item Name</h2>
				<table border="8" id="TABLE1" onclick="return TABLE1_onclick()">
					<tr>
						<td style="width: 84px"><span style="font-size: 10pt">
								Bid Price</span></td>
						<td style="width: 84px"><span style="font-size: 10pt">
								Bid Time</span></td>
						<td style="width: 84px"><span style="font-size: 10pt">
								Customer ID</span></td>	
					</tr>
					<%
					
					rs = stmt1.executeQuery("SELECT   B.BidPrice, B.BidTime, B.CustomerID " +
							"FROM      Item I, Bid B, Auction A " +
							"WHERE   I.Name = '" + itemName + "' AND I.ItemID = A.ItemID AND " +
							"B.AuctionID = A.AuctionID");

						while (rs.next()) {
				%>
					<tr>
						<td style="width: 84px"><span style="font-size: 10pt"><%=rs.getString(1)%></span></td>
						<td style="width: 84px"><span style="font-size: 10pt"><%=rs.getString(2)%></span></td>
						<td style="width: 84px"><span style="font-size: 10pt"><%=rs.getString(3)%></span></td>
					</tr>
					<%
					}
					} catch (Exception e) {
						e.printStackTrace();
						out.print(e.toString());
					} finally {

						try {
							conn.close();
						} catch (Exception ee) {
						}
						;
					}
				%>
				</table> <br></br>
				<p>
					<a href="ManageEmployees.jsp">Back</a>
				</p>
</body>
</html>
<script language="javascript" type="text/javascript">
function ItemName_OnClick()
{	
	document.itemName.submit();
}
</script>